package cn.maihe.elg.operation.service.order;

import cn.maihe.elg.operation.repository.entity.AcceptContent;
import cn.maihe.elg.operation.repository.entity.AcceptContentCondition;
import cn.maihe.elg.operation.service.BaseDaoService;
import cn.maihe.elg.operation.utils.IdGenerate;
import cn.maihe.framework.starter.mybatis.mapper.PlusEntityWrapper;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @Description
 * @Author WJH
 * @Date 2022/04/01
 */
@Service
@Slf4j
public class AcceptContentService extends BaseDaoService<AcceptContent> {


    /**
     * 保存&更新 受理订单信息
     */
    public AcceptContent saveOrUpdateAcceptContent(String acceptOrderNo, Object reqContent) {
        PlusEntityWrapper<AcceptContent> plusEntityWrapper = AcceptContentCondition.builder().andAcceptOrderNoEq(acceptOrderNo).build();
        AcceptContent acceptContent = this.selectOne(plusEntityWrapper);
        if (acceptContent != null) {
            acceptContent.setReqContent(JSON.toJSONString(reqContent));
            this.updateById(acceptContent);
        } else {
            acceptContent = new AcceptContent();
            acceptContent.setId(IdGenerate.getId());
            acceptContent.setAcceptOrderNo(acceptOrderNo);
            acceptContent.setReqContent(JSON.toJSONString(reqContent));
            this.insert(acceptContent);
        }
        return acceptContent;
    }
}
